<?php
	$CI =& get_instance();
	$CI->load->library('totals');
	$this->load->helper('text');
	$unread_message = $CI->totals->new_messages();
	$fname = $this->session->userdata('e_f_name');
	$user_id = $this->session->userdata('userid');
	$lname = $this->session->userdata('e_l_name');
	$cp_authlink = $this->authlink->generate_authlink();
	$mname = $this->session->userdata('e_m_name');
	$usertype = $this->session->userdata('userType');
?>
<nav class="top-bar">
  <section class="top-bar-section">
    <!-- Left Nav Section -->
<ul class="title-area">
<!-- Title Area -->
<li class="name">
	<h1>
		<a href="#" data-tooltip class="has-tip" title="<?=$this->school_name;?>">
		<?php echo $this->school_name !== '' ? word_limiter($this->school_name,4) : '';?>
	</a>
	</h1>
</li>
<!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>


<section class="top-bar-section hide-for-small">
	<ul class="left">
		<li class="divider hide-for-medium-down"></li>
		<li class="name hide-for-medium-down">
			<h1><a href="#" data-tooltip class="has-tip" title="User Account Type">(<?=ucwords($usertype);?> Account)</a></h1>
		</li>
		<li class="divider"></li>
		<!-- <li class="name">
			<h1><a href="#" data-tooltip class="has-tip" title="Current Academic Year/School Year <?=$this->schoolyear_desc ? "( $this->schoolyear_desc " : ''?>)"><i class="icon-calendar icon-white"></i> SY: <?=$this->schoolyear_date;?> <span class="badge badge-important">!</span></a></h1>
		</li> -->
		<li class="name has-dropdown" >
			<h1><a href="#"><i class="icon-calendar icon-white"></i> SY: <?=$this->schoolyear_date;?></a></h1>
			<ul class="dropdown">
				

				<?if(isset($this->available_sy) && $this->available_sy):?>
            
            
            <li><label>Select to Change School Year</label></li>

            <?foreach ($this->available_sy as $k => $sy_v): ?>
            	<li><a class="confirm" title ="Are you sure to change your current school year to <?=$sy_v->sy_from?>-<?=$sy_v->sy_to?> <?=$sy_v->desc ? "( $sy_v->desc )" : '' ?>?" href="<?=site_url('change/set_school_year/'.$sy_v->id.'/'.$cp_authlink);?>"><i class="fa fa-check"></i>&nbsp; <?=$sy_v->sy_from?>-<?=$sy_v->sy_to?> <?=$sy_v->desc ? "( $sy_v->desc )" : '' ?>  </a></li>
            <?endforeach;?>
            <li class="divider"></li>
            <li><a href="<?php echo site_url('change/school_year/'.$user_id.'/'.$cp_authlink);?>" class="">More ...</a></li>

        <?else:?>

        	<li><a href="#">No Available School Year</a></li>

        <?endif;?>
				
				<li class="divider"></li>
        <li><a href="#" data-tooltip class="has-tip" title="Current System Academic Year/School Year"><i class="fa fa-calendar-o"></i>&nbsp; SY: <?=$this->system_school_year->sy_from;?>-<?=$this->system_school_year->sy_to;?></a></li>

      </ul>
		</li>
		<li class="divider"></li>
		<li class="name">
			<h1><a href="#" data-tooltip class="has-tip" title="Current Grading Period"><?=ucwords($this->gperiods_current);?></a></h1>
		</li>
		<li class="name has-dropdown" >
			<a href="<?=site_url('calendar');?>"><i class="icon-calendar icon-white"></i></a>
			<ul class="dropdown">
                  <li><label>Calendar Of Activities</label></li>
                  <li><a href="<?=site_url('calendar/academic');?>">Academic</a></li>
                  <li><a href="<?=site_url('calendar/school');?>">School</a></li>
                  <li><a href="<?=site_url('calendar/section');?>">Section</a></li>
            </ul>
		</li>
		<li class="name">
			<h1><a href="<?=site_url('message');?>"><i class="icon-envelope icon-white"></i><span class="message-notifier"><span class="badge badge-important"><?php echo $unread_message; ?></span></span></a></h1>
		</li>
		<li class="name">
			<a href="<?=site_url('change/set_tool_tip/'.$cp_authlink);?>" data-tooltip class="has-tip" title="Toogle tooltip on or off?"><i class="icon-question-sign icon-white"></i></a>
		</li>
	</ul>
</section>

    <ul class="left show-for-small hide-for-medium-up">
      <li class="divider"></li>
      <li class="has-dropdown"><a href="#">Menu</a>
        <ul class="dropdown">
          <li class="has-dropdown"><a href="#"><?=ucwords(@$fname.' '.@$mname[0].'. '.@$lname);?></a>
            <ul class="dropdown">
			  <?$this->load->view('layouts/_dynamic_topnav_menu')?>
              <li><a href="<?php echo site_url();?>"><i class='icon-white icon-home'></i> Home</a></li>
              <li><a href="<?php echo site_url('change/password/'.$user_id.'/'.$cp_authlink);?>" class="confirm" title="Are you sure you want to change your login password? "><i class='icon-white icon-edit'></i> Change Password</a></li>
              <li><a href="<?=site_url('calendar');?>"><i class="icon-calendar icon-white"> Calendar</i></a></li>
			</ul>
          </li>
         <li class="divider"></li>
		<li>
			<a href="#" data-tooltip class="has-tip" title="User Account Type">(<?=ucwords($usertype);?> Account)</a>
		</li>
		<li class="divider"></li>
		<li>
			<a href="#" data-tooltip class="has-tip" title="Current Academic Year/School Year"><i class="icon-calendar icon-white"></i> SY: <?=$this->schoolyear_date;?></a>
		</li>
		<li class="divider"></li>
		<li>
			<a href="#" data-tooltip class="has-tip" title="Current Grading Period"><?=ucwords($this->gperiods_current);?></a>
		</li>
        </ul>
      </li>
      <li class="divider"></li>

      <li class="has-dropdown"><a href="#">Misc</a>
        <ul class="dropdown">
	        <li><a href="<?php echo site_url('auth/logout');?>" class="confirm" title="Are you sure you want to log out?"><i class='icon-white icon-off'></i> Logout </a></li>
	        <li><a href="<?php echo site_url('filemanager');?>"><i class='icon-white icon-hdd'></i> File Manager</a></li>
        </ul>
      </li>
    </ul>
    <!-- Right Nav Section -->
    <ul class="right hide-for-small">
      <li class="has-dropdown"><a href="#"><?=ucwords(@$fname.' '.@$mname[0].'. '.@$lname);?></a>
        <ul class="dropdown left">
		  <?$this->load->view('layouts/_dynamic_topnav_menu')?>
		  <li class="left"><a href="<?php echo site_url();?>"><i class='icon-white icon-home'></i> Home</a></li>
		  <li class="left"><a href="<?php echo site_url('filemanager');?>"><i class='icon-white icon-hdd'></i> File Manager</a></li>
		  <li><a href="<?php echo site_url('change/school_year/'.$user_id.'/'.$cp_authlink);?>" class="confirm" title="Are you sure you want to change your current school year? "><i class="fa fa-calendar-o"></i>&nbsp; Change School Year</a></li>
          <li class="left"><a href="<?php echo site_url('change/password/'.$user_id.'/'.$cp_authlink);?>" class="confirm" title="Are you sure you want to change your login password? "><i class='icon-white icon-edit'></i> Change Password</a></li>
          <li class="divider"></li>
          <li class="left"><a href="<?php echo site_url('auth/logout');?>" class="confirm" title="Are you sure you want to log out?"><i class='icon-white icon-off'></i> Logout </a></li>
		</ul>
      </li>
	</ul>
  </section>
</nav>
<!--<script src="<?=script_url('custom/messagenotify');?>"></script>-->
<script>
$(document).ready(function(){
	var span = $('.message-notifier');
	var currentCount = span.text();

	setInterval(function(){
		span.addClass('badge badge-important');
		span.text("<?php echo $unread_message; ?>");
	},4000);
});
</script>